package com.example.fragmentdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

/**
 * Created by zengfansheng on 2016/3/28 0028.
 */
public class Fragment2fg extends BaseFragment {

    EditText etData2;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment2_layout, null);
        etData2 = (EditText) view.findViewById(R.id.et_data2);
        return view;
    }

    @Override
    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
        super.onViewStateRestored(savedInstanceState);
        if (savedInstanceState != null) {
            String data2 = savedInstanceState.getString("data");
            Log.i(MainActivity.TAG, "onViewStateRestored: data2:" + data2);
            etData2.setText(data2 + "---hahah,我家的");
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        Editable data2 = etData2.getText();
        outState.putString("data", data2.toString());
    }

}
